﻿@using Model;
@{
    Layout = "~/Admin/_AdminSiteLayout.cshtml";
    Page.Title = "View Questions";

    List<SelectListItem> listItem = new List<SelectListItem>();

    List<Question> questions = SiteHelper.GetAllQuestions();

    List<Question> questionList = new List<Question>();

    foreach (Question item in questions)
    {
        if (string.IsNullOrEmpty(item.AnswerStatus))
        {
            // questions.Remove(item);
            item.AnswerStatus = SiteHelper.GetStatus(item.IsAnswered);
            questionList.Add(item);
        }
    }
    questions = questionList;

    if (UrlData[0] != "")
    {
        bool isDeleted = UrlData[0].AsBool();
        //bool isDeleted = Request.Form["status"].AsBool();

        if (isDeleted)
        {
    <p class="message success">
        Question deleted Successfully
    </p>
        }
        else
        {
    <p class="message error">
        Cannot delete requested Question
    </p>
        }
    }
}
@{
    var grid = new WebGrid(source: questions, rowsPerPage: WebSite.RowsPerPage);
    <fieldset>
        <legend>Question List</legend>
        <div id="grid">
            @grid.GetHtml(
                tableStyle: "gridTable",
                headerStyle: "gridTableHeader",
                rowStyle: "rowstyle",
                alternatingRowStyle: "alternaterowstyle",
                columns: grid.Columns(
                grid.Column("Questions", "Questions"),
                grid.Column("TotalAnsweringTime", "Total Answering Time", style: "text-align-center"),
                grid.Column("IsAnswered", "Is Answered", style: "text-align-center"),
                                           grid.Column("AnswerStatus", " Answer Status", style: "text-align-center AnswerStatus"),
                grid.Column("ReadingClass", "Reading Class", style: "text-align-center"),
                grid.Column("Results", format: @<span>@item.Results.ToString("N")</span>, style: "text-align-center"),
                grid.Column("UserId", "Answer By", format: @<a href=@Href("~/Account/ViewProfile/" + @item.UserId)>
                    <img src="../Images/ico-profile.png" alt="Details" /></a>, style: "text-align-center"),
                grid.Column("Details", "", format: @<a href="QuestionDetails/@item.Id">
                    <img src="../Images/ico-view-detailed.png" alt="Details" /></a>, style: "text-align-center"),
                grid.Column("Delete", "", format: @<a href="DeleteQuestion/@item.Id">
                    <img src="../Images/ico-delete.png" alt="Delete" /></a>, style: "text-align-center")
            )
            )
        </div>
        <div>
            <span><a href="@Href("~/Admin/ReloadAllQuestion")">Reload All Question</a> </span>
        </div>
    </fieldset>
}
<script src="@Href("~/Scripts/jquery-1.6.2.min.js")" type="text/javascript"></script>
<script src="@Href("~/Scripts/Answer-table-color.js")" type="text/javascript"></script>